package uncharted

import (
	"time"

	"public.com/goutil/syncUtil"
)

// 领地点信息
type TerritoryPoint struct {
	// 地图id
	mapId int8

	// 点序号
	pointId int

	// 匹配数据
	playerData *MatchPlayer

	// 占领的起始时间点
	territoryTime time.Time

	// 是否正在进行领地争夺
	isTerritorying bool

	// 领地锁对象
	territoryLock *syncUtil.RWLocker
}

// 设置领地占领玩家
// playerData
// territoryTime:占领的起始时间点
func (this *TerritoryPoint) SetTerritoryPlayer(playerData *MatchPlayer, territoryTime time.Time) {
	this.playerData = playerData
	this.territoryTime = territoryTime
}

// 占领此领地的玩家Id
func (this *TerritoryPoint) PlayerId() string {
	if this.playerData == nil {
		return ""
	}

	return this.playerData.Id
}

// 领地占领时间
func (this *TerritoryPoint) TerritoryTime() time.Time {
	return this.territoryTime
}

// 获取玩家数据
func (this *TerritoryPoint) PlayerData() *MatchPlayer {
	return this.playerData
}

// 获取锁对象
func (this *TerritoryPoint) LockItem() *syncUtil.RWLocker {
	return this.territoryLock
}

// 查看是否正在进行领地争夺
func (this *TerritoryPoint) IsTerritorying() bool {
	return this.isTerritorying
}

// 设置是否正在进行领地争夺
func (this *TerritoryPoint) SetIsTerritorying(isTerritorying bool) {
	this.isTerritorying = isTerritorying
}

// 地图Id
func (this *TerritoryPoint) MapId() int8 {
	return this.mapId
}

// 节点序号
func (this *TerritoryPoint) PointId() int {
	return this.pointId
}

// 获取拷贝对象
// 返回值:
// *TerritoryPoint:拷贝结果
func (this *TerritoryPoint) GetCopy() *TerritoryPoint {
	result := *this

	result.territoryLock = syncUtil.NewRWLocker()
	if result.playerData != nil {
		result.playerData = result.playerData.GetCopy()
	}

	return &result
}

// 新建领地点对象
// _mapId:地图Id
// _pointId:点Id
// 返回值:
// *TerritoryPoint:点对象
func NewTerritoryPoint(_mapId int8, _pointId int) *TerritoryPoint {
	return &TerritoryPoint{
		mapId:         _mapId,
		pointId:       _pointId,
		territoryLock: syncUtil.NewRWLocker(),
	}
}
